<template>
    <div>
        <div class="modal fade" id="modal-send-message" tabindex="-1" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button " class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">
                            发送私信
                        </h4>
                    </div>

                    <div class="modal-body">
                        <div class="alert alert-success" v-if="status">发送成功</div>
                        <textarea class="form-control" name="" id="" cols="15" rows="10" v-model="body"></textarea>
                    </div>

                    <!-- Modal Actions -->
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" @click="cancel">取消</button>
                        <button type="button" class="btn btn-primary" @click="send">发送</button>
                    </div>
                </div>
            </div>
        </div>
        <button
                class="btn btn-default pull-right"
                @click="showSendMessageBox"
        >发送私信
        </button>
    </div>

</template>

<script>
    export default {
        props: ['user'],
        mounted() {
        },
        data() {
            return {
                body: '',
                status: false
            }
        },
        computed: {},
        methods: {
            showSendMessageBox() {
                $('#modal-send-message').modal('show');
            },
            cancel() {
                $('#modal-send-message').modal('hide');
            },
            send() {
                axios.post('/api/message/store', {'to_user_id': this.user, 'body': this.body}).then(response => {
                    this.status = response.data;
                    // TODO animate
                    this.cancel();
                })
            }
        }
    }
</script>